package rlm.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;

public class PrecompilePackage {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		if (args.length < 2){
			System.out.println("Usage: PrecompilePackage <package-file-name> <drl-files>+");
			System.exit(1);
		}
		
		String pkgFile = args[0];
		
		KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
		for(int i = 1; i < args.length; i++){
			kbuilder.add(ResourceFactory.newFileResource(args[i]), ResourceType.DRL);
		}
		
		OutputStream os = new FileOutputStream( pkgFile );
		ObjectOutputStream oos = new ObjectOutputStream( os );
		oos.writeObject( kbuilder.getKnowledgePackages() );
		oos.close();
	}

}
